#include "commond.hpp"


//server端 发送信息
int main()
{
    //获取shm
    key_t k = GetKey();
    std::cout << "key_t:" << k << std::endl;
    int shmid = GetShm(k);
    std::cout << "shmid:" << shmid << std::endl;

    //与共享内存建立联系
    char* start = (char*)AttachShm(shmid);
    printf("attach success, attach start address:%p\n", start);
    
    //开始通信
    const char* buffer = "hello server, i am another process";
    int count = 1;
    pid_t id = getpid();
    while(true)
    {
        snprintf(start, MAX_SIZE, "%s, mypid[%d], msg第[%d]条\n", buffer, id, count++);
        sleep(1);
    }



    //与指定共享内存断联
    DetachShm(start);
    return 0;
}